<template>
  <div class="x-unit" @click.self="closeMask" :style="{height:`${deviceH}px`}">
    <div class="unit-ctx" :style="{'background-image':`url(${modelBg})`}">
      <div class="ctx-title">警网联动力量</div>
      <div class="ctx-info">
        <div class="info-type">
          <div class="type-title" @click="slecttype()" style="cursor: pointer;">
            <img src="../../assets/images/power_icon.png" alt="">
            <div>
              <p>人员总数</p>
              <p>{{alltotal}}</p>
            </div>
          </div>
          <ul v-if="SecurityTypeEchartsData.length" class="type-list">
            <li v-for="item in SecurityTypeEchartsData" :key="item.name" @click="slecttype(item.name)" class="type-list-rs" v-if="item.value>0"
              style="cursor: pointer;">
              <div class="rs-name">
                <span class="name">{{item.name}}</span>
                <span class="number">{{item.value}}</span>
              </div>
              <div class="rs-process">
                <div class="process" :style="{width:`${(item.value/alltotal)*100}%`}"></div>
              </div>
            </li>
          </ul>
        </div>
        <div class="info-table">
          <div class="table-rs">
            <!-- <div class="table-header">
              <div class="header-select">
                <x-select @selectItem="selectPost" :name="peopleTypeName || '人员类型'" :listItem="postList" />
              </div>

              <div @click="searchEvent" class="header-btn">搜索</div>
            </div> -->
            <ul class="table-list">
              <li class="list-item">
                <div class="item-no">序号</div>
                <div class="item-post">人员类型</div>
                <div class="item-name">姓名</div>
                <div class="item-phone">联系电话</div>
                <div class="item-state">地址</div>
              </li>
              <li v-for="item,i in SecurityPageEchartsData" :key="item.id" class="list-item">
                <div class="item-no">{{i+1+pageSize*(pageNum-1)}}</div>
                <div class="item-post">{{item.peopleType}}</div>
                <div class="item-name">{{new String().hideName(item.name)}}</div>
                <div class="item-phone">{{item.phone}}</div>
                <div class="item-state" :title="item.address">{{item.address}}</div>
              </li>
            </ul>
          </div>
          <div v-if="allpage>0" class="table-footer">
            <x-page @currentChange="currentChange" :currentPage="pageNum" :page-size="5" :allpage="allpage" :total-num="false" />
          </div>
        </div>
      </div>

    </div>
  </div>
</template>
<script>
  import XPage from '@/components/xpage';
  import XSelect from '@/components/xselect'
  import {
    GetSecurityTotleAndType,
    GetSecurityInfoForPage,
    GetDictDataEnum
  } from '@/api/peopleApi';
  export default {
    name: "xpowermodel",
    props: {
      id: {
        type: String,
        default: ""
      },
      code: {
        type: String,
        default: ""
      }
    },
    computed: {

    },
    data() {
      return {
        modelBg: require('@/assets/images/modelBg.png'),
        deviceH: 0,
        pageSize: 12,
        pageNum: 1,
        name: "",
        peopleType: "",
        peopleTypeName: "",
        state: "",
        stateName: "",
        SecurityTypeEchartsData: [],
        SecurityPageEchartsData: [],
        total: 0,
        allpage: 0,
        postList: [],
        stateList: [],
        alltotal:0
      }
    },
    beforeMount() {
      let h = document.documentElement.clientHeight || document.body.clientHeight;
      this.deviceH = h
    },
    mounted() {
      Promise.all([this.GetPowerData(), this.GetDictDataEnumPost(), this.GetDictDataEnumState()])
    },
    components: {
      XPage,
      XSelect
    },
    methods: {
      async GetPowerData() {

        try {
          let camerquery = {
            code: this.code,
            id: this.id,

          }
          let pagequery = {
            code: this.code,
            id: this.id,
            peopleType: this.peopleType,
            name: this.name,
            state: this.state,
            pageNum: this.pageNum,
            pageSize: this.pageSize
          }
          console.log(pagequery)
          this.SecurityTypeEchartsData = await GetSecurityTotleAndType(camerquery)
          console.log(this.SecurityTypeEchartsData)
          const res = await GetSecurityInfoForPage(pagequery)
          if (res.data == null) {
            this.total = 0
            this.SecurityPageEchartsData = []
            this.allpage = 1
          } else {
            if(this.peopleType==''){
              this.alltotal = res.data.total
            }
            this.total = res.data.total
            this.SecurityPageEchartsData = res.data.list
            console.log(this.SecurityPageEchartsData)
            this.allpage = Math.ceil(this.total / this.pageSize)
          }
        } catch (error) {
          this.$message({
            type: "error",
            message: error
          })
        }
      },
      //获取职责
      async GetDictDataEnumPost() {
        try {
          const res = await GetDictDataEnum('security_personnel_type')
          res.unshift({
            enumName: "全部",
            id: ""
          })
          this.postList = res
        } catch (error) {
          this.$message({
            type: "error",
            message: error
          })
        }
      },
      //获取类型
      async GetDictDataEnumState() {
        try {
          const res = await GetDictDataEnum('security_personnel_status')
          res.unshift({
            enumName: "全部",
            id: ""
          })
          this.stateList = res
        } catch (error) {
          this.$message({
            type: "error",
            message: error
          })
        }
      },
      //关闭
      closeMask() {
        this.$emit("closeMask")
      },
      //分页
      currentChange(n) {
        this.pageNum = n;
        this.GetPowerData()
      },
      //选择职责
      selectPost(name, id) {
        this.peopleTypeName = name
        this.peopleType = id
      },
      slecttype(name){
        if(name){
        this.peopleTypeName = name;
        this.postList.map(item=>{
          if(item.enumName==name){
            this.peopleType=item.id
            this.GetPowerData();
          }
        })
      }else{
        //全部
        this.peopleTypeName = '';
        this.peopleType=''
        this.GetPowerData();
      }
      },
      //选择状态
      selectState(name, id) {
        this.stateName = name
        this.state = id

      },
      //搜索
      searchEvent() {
        this.GetPowerData()
      },

    }
  }
</script>
<style lang="less" scoped>
  .x-unit {
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, .8);
    z-index: 1000;
     .item-no {
                width: 50px;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
                text-align: center;
              }

    .unit-ctx {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      left: 0;
      right: 0;
      margin: 0 auto;
      width: 1177px;
      height: 800px;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      background-position: center;
      padding: 10px 30px;
      box-sizing: border-box;

      .ctx-title {
        width: 100%;
        padding-top: 10px;
        box-sizing: border-box;
        font-family: PingFangSC-Medium;
        font-size: 24px;
        color: #E9E9E9;
        letter-spacing: 4.8px;
        text-align: center;
        box-sizing: border-box;
      }

      .ctx-info {
        width: 100%;

        height: 748px;
        padding-top: 20px;
        box-sizing: border-box;
        display: flex;
        justify-content: space-around;
        align-items: flex-start;

        .info-type {
          flex: 1;

          .type-title {
            width: 100%;
            font-family: PingFangSC-Medium;
            font-size: 18px;
            color: #69D3DA;
            letter-spacing: 0;
            text-align: left;
            overflow: hidden;

            img {
              float: left;
            }

            div {
              float: left;
              margin-left: 20px;
              margin-top: -11px;
            }
          }

          .type-list {
            width: 100%;
            padding: 0;
            margin-top: 26px;
            list-style: none;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            box-sizing: border-box;

            .type-list-rs {
              width: 100%;
              list-style: none;
              margin-bottom: 20px;

              .rs-name {
                width: 100%;
                display: flex;
                justify-content: space-around;
                align-items: center;
                font-family: PingFangSC-Regular;
                font-size: 12px;
                color: #E5E5E5;
                margin-bottom: 5px;

                .name {
                  flex: 1;
                  text-align: left;
                }

                .number {
                  flex: 1;
                  text-align: right;
                }
              }

              .rs-process {
                width: 100%;
                height: 6px;
                border-radius: 4px;
                background: #333333;

                .process {
                  transition: width .3s ease-in-out;
                  height: 100%;
                  border-radius: 4px;
                  background-image: linear-gradient(270deg, #68E0CF 0%, #209CFF 100%);
                }
              }
            }
          }
        }

        .info-table {
          flex: 3;
          height: 659px;
          padding-left: 40px;
          box-sizing: border-box;

          .table-rs {
            width: 100%;
            height: 562px;
            overflow-y: auto;

            .table-header {
              width: 100%;
              height: 36px;
              display: flex;
              justify-content: flex-start;
              align-items: center;
              position: relative;

              .header-item {
                width: 186px;
                height: 100%;
                border: none;
                outline: none;
                background: #06121D;
                border: 1px solid rgba(62, 178, 215, 0.00);
                border-radius: 4px;
                font-size: 14px;
                color: #fff;
                padding: 0 14px;
                box-sizing: border-box;

                .input {
                  font-size: 14px;
                  color: #fff;
                  width: 100%;
                  height: 100%;
                  border: none;
                  outline: none;
                  background: transparent;
                }
              }

              .header-select {
                width: 186px;
                height: 100%;
                background: #06121D;
                border: 1px solid rgba(62, 178, 215, 0.00);
                border-radius: 4px;
                font-size: 14px;
                color: #fff;
                padding: 0 14px;
                box-sizing: border-box;
                display: flex;
                justify-content: space-between;
                align-items: center;

                .select-name {
                  width: calc(100% - 20px);
                  overflow: hidden;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                  word-break: normal;
                  text-align: left;
                }

                .iconfont {
                  width: 20px;
                  text-align: right;
                  font-size: 14px;
                  color: #fff;
                  font-weight: 600;
                }
              }

              .header-more {
                width: 56px;
                margin-left: 20px;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #72EDF5;
                line-height: 28px;
                text-decoration: underline;
              }

              .header-btn {
                cursor: pointer;
                position: absolute;
                top: 50%;
                transform: translateY(-50%);
                right: 0;
                width: 66px;
                height: 100%;
                background: #72EDF5;
                border-radius: 4px;
                text-align: center;
                line-height: 36px;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #000000;
              }
            }

            .table-list {
              width: 100%;
              list-style: none;
              padding: 0;
              margin-top: 15px;

              .list-item {
                padding: 0;
                margin: 0;
                list-style: none;
                width: 100%;
                display: flex;
                justify-content: space-between;
                align-items: center;
                height: 36px;

                &:nth-of-type(2n+1) {
                  background: #06121D;

                }

                &:nth-of-type(2n) {
                  background: transparent;
                }

                .item-name {
                  width: 120px;
                  padding-left: 33px;
                  box-sizing: border-box;
                  height: 100%;
                  font-family: PingFangSC-Regular;
                  font-size: 14px;
                  color: #FFFFFF;
                  line-height: 36px;
                  text-align: left;
                }

                .item-post {
                  width: 100px;
                  padding-left: 33px;
                  box-sizing: border-box;
                  height: 100%;
                  font-family: PingFangSC-Regular;
                  font-size: 14px;
                  color: #FFFFFF;
                  line-height: 36px;
                  text-align: left;
                }

                .item-phone {
                  width: 150px;
                  padding-left: 33px;
                  box-sizing: border-box;
                  height: 100%;
                  font-family: PingFangSC-Regular;
                  font-size: 14px;
                  color: #FFFFFF;
                  line-height: 36px;
                  text-align: left;
                }

                .item-state {
                  width: 350px;
                  padding-left: 33px;
                  box-sizing: border-box;
                  height: 100%;
                  font-family: PingFangSC-Regular;
                  font-size: 14px;
                  color: #FFFFFF;
                  line-height: 36px;
                  text-align: left;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                }

              }
            }
          }

          .table-footer {
            width: 100%;
            padding-top: 60px;
            box-sizing: border-box;
            display: flex;
            justify-content: flex-end;
          }
        }
      }
    }
  }
</style>
